package com.hxd.otc.base;

import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.mvp.contract.BaseRecyclerContract;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lzy on 2018/6/7 0007.
 * description ${TODO}
 * <p>
 * Changed by somebody on 2018/6/7 0007
 * description ${TODO}
 */
public abstract class BaseRecyclerPresenter<V extends BaseRecyclerContract.View<A, T>, A extends BaseAdapter, T> extends BasePresenter<V> implements BaseRecyclerContract.Presenter<T> {
    public static final int DEFAULT_INDEX = 1;
    protected int mPageIndex = DEFAULT_INDEX;

    public BaseRecyclerPresenter(V v) {
        super(v);
    }

    @Override
    public void onRefresh() {
        mPageIndex = DEFAULT_INDEX;
        mView.setEnableLoadMore(mView.isEnableLoadMore());
        loadData(true);
    }

    @Override
    public void onLoadMore() {
        loadData(false);
    }

    @Override
    public void onLoadDataSuccess(boolean isRefresh, List<T> data) {
        if (data == null) data = new ArrayList<>();
        mPageIndex++;
        mView.onLoadDataSuccess(isRefresh, data);
        mView.setEnableLoadMore(mView.isEnableLoadMore() && data.size() >= getPageSize());
    }

    public int getPageSize() {
        return 15;
    }

    @Override
    public void onLoadDataFail(boolean isRefresh,String msg) {
        mView.onLoadDataFail( isRefresh,msg);
    }
    @Override
    public void start() {
    }
}
